﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using AutumnEngine.Modules;
using System.Diagnostics;
using AutumnEngine;

namespace AutumnEngine.Modules
{
    /// <summary>
    /// Controls touchscreen functions for the zune.
    /// </summary>
    public class TouchscreenInputModule : Module
    {
        TouchCollection last, current;

        public override void Create()
        {
#if ZUNE
            current = TouchPanel.GetState();
            last = current;
#else

#endif
            base.Create();
        }

        public override void Update()
        {
#if ZUNE
            last = current;
            current = TouchPanel.GetState();
#else

#endif
            base.Update();
        }

        /// <summary>
        /// Gets the current touches.
        /// </summary>
        /// <value>The current touches.</value>
        public TouchCollection CurrentTouches
        {
            get { return current; }
        }

        /// <summary>
        /// Gets the last touches.
        /// </summary>
        /// <value>The last touches.</value>
        public TouchCollection LastTouches
        {
            get { return last; }
        }

        /// <summary>
        /// Checks if the touch is registered.
        /// </summary>
        /// <param name="indx">The zero based index.</param>
        /// <returns></returns>
        public bool DoesTouchExist(int index)
        {
#if ZUNE
            if (this.current.Count >= index + 1)
                return true;
#endif
            return false;
        }

        /// <summary>
        /// Gets the total touches, starting at 0 for none and 1 for one.
        /// </summary>
        /// <value>The total touches.</value>
        public int TotalTouches
        {
            get
            {
#if ZUNE
                return this.current.Count;
#else
                return 0;
#endif
            }
        }

    }
}


#if !ZUNE
namespace Microsoft.Xna.Framework.Input
{
    public class TouchCollection
    {
        public TouchLocation this[int index]
        {
            get { return new TouchLocation(); }
        }
        public const int Count = 0;
    }

    public class TouchLocation
    {
        public Vector2 Position = Vector2.Zero;
        public float Pressure = 0f;
        public int ID = 0;
        public bool TryGetPreviousLocation(out TouchLocation das)
        {
            das = null;
            return false;
        }

    }
}
#endif